﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.Ray
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System;
using System.Globalization;

#nullable disable
namespace UnityEngine
{
  /// <summary>
  ///   <para>Representation of rays.</para>
  /// </summary>
  public struct Ray : IFormattable
  {
    private Vector3 m_Origin;
    private Vector3 m_Direction;

    /// <summary>
    ///   <para>Creates a ray starting at origin along direction.</para>
    /// </summary>
    /// <param name="origin"></param>
    /// <param name="direction"></param>
    public Ray(Vector3 origin, Vector3 direction)
    {
      this.m_Origin = origin;
      this.m_Direction = direction.normalized;
    }

    /// <summary>
    ///   <para>The origin point of the ray.</para>
    /// </summary>
    public Vector3 origin
    {
      get => this.m_Origin;
      set => this.m_Origin = value;
    }

    /// <summary>
    ///   <para>The direction of the ray.</para>
    /// </summary>
    public Vector3 direction
    {
      get => this.m_Direction;
      set => this.m_Direction = value.normalized;
    }

    /// <summary>
    ///   <para>Returns a point at distance units along the ray.</para>
    /// </summary>
    /// <param name="distance"></param>
    public Vector3 GetPoint(float distance) => this.m_Origin + this.m_Direction * distance;

    /// <summary>
    ///   <para>Returns a formatted string for this ray.</para>
    /// </summary>
    /// <param name="format">A numeric format string.</param>
    /// <param name="formatProvider">An object that specifies culture-specific formatting.</param>
    public override string ToString() => this.ToString((string) null, (IFormatProvider) null);

    /// <summary>
    ///   <para>Returns a formatted string for this ray.</para>
    /// </summary>
    /// <param name="format">A numeric format string.</param>
    /// <param name="formatProvider">An object that specifies culture-specific formatting.</param>
    public string ToString(string format) => this.ToString(format, (IFormatProvider) null);

    /// <summary>
    ///   <para>Returns a formatted string for this ray.</para>
    /// </summary>
    /// <param name="format">A numeric format string.</param>
    /// <param name="formatProvider">An object that specifies culture-specific formatting.</param>
    public string ToString(string format, IFormatProvider formatProvider)
    {
      if (string.IsNullOrEmpty(format))
        format = "F2";
      if (formatProvider == null)
        formatProvider = (IFormatProvider) CultureInfo.InvariantCulture.NumberFormat;
      return UnityString.Format("Origin: {0}, Dir: {1}", (object) this.m_Origin.ToString(format, formatProvider), (object) this.m_Direction.ToString(format, formatProvider));
    }
  }
}
